//
//  lyricsParseTools.swift
//  QQMusic
//
//  Created by xmg on 16/9/8.
//  Copyright © 2016年 wlis. All rights reserved.
//

import UIKit

class lyricsParseTools: NSObject {

    /** 根据路径解析歌词 */
    class func lyricsToolsWithFileName(fileName : String) ->[lyricsItem]? {
        guard let lrcPath = NSBundle.mainBundle().pathForResource(fileName, ofType: nil) else{return nil}
        guard let lrcString = try? String(contentsOfFile: lrcPath) else{return nil}
        
        /** 解析字符串 */
        let lrcStrings = lrcString.componentsSeparatedByString("\n")
        var tempArray = [lyricsItem]()
        for lrcStr in lrcStrings{
            /** 过滤歌词头 */
            if lrcStr.containsString("[ti:") || lrcStr.containsString("[ar:") || lrcStr.containsString("[al:") || !lrcStr.containsString("[") {
                continue
            }
            let lrcI = lyricsItem(lrcStr: lrcStr)
            tempArray.append(lrcI)
        }
        return tempArray
    }
}
